package com.lpgu.jpa.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import java.util.Optional;

/**
 * @author: lpgu
 * @describe:Config
 * @createAt: 2022/1/3 17:27
 */
@Configuration
@EnableJpaAuditing
public class Config {

    @Bean
    public AuditorAware<String> auditorAware(){
        AuditorAware<String> zhangsan = new AuditorAware<String>() {

            @Override
            public Optional<String> getCurrentAuditor() {
                //当前用户 session redis
                return Optional.of("zhangsan");
            }
        };
        return zhangsan;
    }
}
